﻿using Sc.Domain;
using Sc.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

namespace Sc.Web.Controllers
{
    public class CheckTypeController : BaseController
    {
        /// <summary>
        /// 车辆检查列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, 3);
            return View();
        }
        /// <summary>
        /// 获取检查列表
        /// </summary>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns></returns>
        public JsonResult GetPageData(int pageSize, int pageIndex)
        {
            var orgz = Convert.ToInt32(Request.Params["orgz"]);
            var start = Request.Params["start"];
            var end = Request.Params["end"];
            var carNo = Request.Params["carNo"];
            var data = new CheckTypeService().GetList(orgz, pageSize, pageIndex, start, end, carNo);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 创建检查登记
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateCheckType()
        {
            ViewData["type"] = new BaseItemService().GetListByType(3);
            return View();
        }
        /// <summary>
        /// 修改检查登记
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateCheckType()
        {
            ViewData["type"] = new BaseItemService().GetListByType(3);
            ViewData["ent"] = new CheckTypeService().GetModel(Convert.ToInt32(Request.Params["id"]));
            return View();
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        public int SaveCheckType()
        {
            string ent = Request.Params["data"];
            JavaScriptSerializer json = new JavaScriptSerializer();
            var model = json.Deserialize<CheckType>(ent);
            model.UserId = UserLogin.UserId;
            return new CheckTypeService().Add(model) ? 1 : 0;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <returns></returns>
        public int SaveUpdateCheckType()
        {
            string ent = Request.Params["data"];
            JavaScriptSerializer json = new JavaScriptSerializer();
            var model = json.Deserialize<CheckType>(ent);
            model.UserId = UserLogin.UserId;
            return new CheckTypeService().Update(model) ? 1 : 0;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids">业务ID</param>
        /// <returns></returns>
        public int DeleteCheckType(string ids)
        {
            return new CheckTypeService().DeleteList(ids) ? 1 : 0;
        }
	}
}